package com.snake.springboot.custom.service.impl.base;

import com.github.pagehelper.Page;
import com.snake.springboot.custom.api.model.base.CustPointsFlowModel;
import com.snake.springboot.custom.api.request.base.CustPointsFlowQuery;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.service.base.CustPointsFlowService;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustPointsFlowDO;
import com.snake.springboot.custom.dao.mybatis.mappers.base.CustPointsFlowMapper;
import com.snake.springboot.custom.service.assemble.base.CustPointsAssemble;
import com.snake.springboot.custom.service.utils.PageUtils;
import org.snake.common.result.ReturnList;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustPointsFlowServiceImpl implements CustPointsFlowService{

    @Autowired
    private CustPointsFlowMapper flowMapper;

    @Override
    public CustPointsFlowModel addCustPointsFlow(CustPointsFlowModel model) {
        CustPointsFlowDO flowDO = CustPointsAssemble.flowDOAss(model,true);
        flowMapper.insert(flowDO);
        return model;
    }

    @Override
    public void modifyCustPointsFlow(CustPointsFlowModel model) {
        CustPointsFlowDO flowDO = CustPointsAssemble.flowDOAss(model,false);
        flowMapper.update(flowDO);
    }

    @Override
    public void removeCustPointsFlow(String id) {
        flowMapper.delete(id);
    }

    @Override
    public ReturnList<CustPointsFlowModel> queryCustPointsFlowList(PageQuery<CustPointsFlowQuery> params) {
        Page<Object> objects = PageUtils.forcePage(params.getPage());
        CustPointsFlowDO queryDO = CustPointsAssemble.flowDOAss(params.getParams());
        List<CustPointsFlowDO> list = flowMapper.queryList(queryDO);
        List<CustPointsFlowModel> modelList = ListUtils.copy(list, CustPointsFlowModel.class);
        return new ReturnList<>(modelList,objects.getTotal());
    }
}
